import { Widget, _decorator, Node, Sprite, Label } from 'cc';
import { SkillType } from '../enum/SkillType';
import { SkillMgr } from '../manager/SkillMgr';
import { GameMgr } from '../manager/GameMgr';
import { UIBase } from '../scriptBase/UIBase';
import { CfgSkillInfo } from '../config/CfgSkillInfo';
import { ResMgr } from '../manager/ResMgr';
import { Bundle } from '../enum/Bundle';
import { AdMgr } from '../manager/AdMgr';
const { ccclass, property, requireComponent } = _decorator;

@ccclass('UI/UIGetSkill')
@requireComponent(Widget)
export class UIGetSkill extends UIBase {

    @property(Node)
    public notNode: Node = null;

    @property(Node)
    public timeNode: Node = null;

    @property(Label)
    public timeLab: Label = null;

    @property(Label)
    public timeLab2: Label = null;

    @property(Label)
    public countLab: Label = null;

    // private icon: Sprite = null
    // private lbTitle: Label = null
    // private lbDesc: Label = null

    private skill: SkillType = null

    protected onLoad(): void {
        // this.icon = this.findComp('Icon', Sprite)
        // this.lbTitle = this.findComp('LbTitle', Label)
        // this.lbDesc = this.findComp('LbDesc', Label)
    }

    public onOpen(data?: unknown): void {
        GameMgr.Pause = true
        this.skill = data as SkillType

        this.notNode.active = true;
        this.timeNode.active = false;
        this.refresh();

        // const skillInfo = CfgSkillInfo[this.skill]
        // this.lbTitle.string = skillInfo.name
        // this.lbDesc.string = skillInfo.desc
        // this.icon.spriteFrame = ResMgr.getSpriteFrame(Bundle.Icon, skillInfo.icon)
    }

    refresh(){
        //this.countLab.string = SkillMgr.skillCnt(SkillType.FreezeTime) + "/3";
    }

    public onClose(data?: unknown): void {
        GameMgr.Pause = false
    }

    protected onBtnGetClick(): void {
        AdMgr.showRewardedVideo(() => {
            SkillMgr.addSkill(this.skill)
            this.refresh();
            // this.close()
        })
    }

}


